package initialization;

import ga.GAInfo;
import ga.Individual;

import java.io.File;
import java.util.Calendar;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;


import mdr.MethodDependences;
import model.Filter;
import model.TestClusterBuilder;
import operations.Operation;
import util.GAConfig;
import util.GAOperationsConfig;
import util.Log;
import util.Randomness;

public class Testmain {
	public static void main(String[] args) {
		String logFilePath = "c:/MAMDA/MAMDA2014/temp/CrossOver.txt";
		Log.logConfig(logFilePath);
		new File(logFilePath).getAbsolutePath();
		
		
	       GAInfo     gaInfo     = new GAInfo();
			long startTime = Calendar.getInstance().getTimeInMillis();
			gaInfo.setTestTimeOut(60 * 500);
			 gaInfo.setTestTimeOut( 60 * 1000*10); ;
				gaInfo.setStartTime(startTime);

				 PopulationInitializer populationInitializer = GAOperationsConfig.getPopulationInitializer();

		Randomness.reset(10);
		
		 Set<Class<?>> allClasses = new LinkedHashSet<Class<?>>();
	      //get class from file
	      allClasses.addAll(TestClusterBuilder.readClassFromFile());

	      
	      TestClusterBuilder tCluster = new TestClusterBuilder(allClasses);
			 Set<Class<?>> cluster = new LinkedHashSet<Class<?>>();
				for(String cName:tCluster.getCluster().keySet()){
					Class<?> cls=tCluster.getCluster().get(cName).getClazz();
					if(Filter.isPrimitiveOrStringType(cls))continue;
					if(cls.getName().startsWith("java.")) continue;
					if(cls.getName().startsWith("sun.")) continue;
					if(cls.getName().contains("$")) continue;
					if(!Filter.canUse(cls))continue;
					cluster.add(cls);
				}

			MethodDependences recommender = new MethodDependences(cluster);
			 recommender.buildDependence(tCluster.getStatements());
			 System.out.println("Finishing method dependence model building");
			gaInfo.setMethodRelations(recommender);
			 populationInitializer.setExtraInfo(gaInfo);	
	      List<Operation> initialConstructors=new LinkedList<Operation>();
	      Individual[] population = populationInitializer.createPopulation();
	      
	      System.out.println(initialConstructors.toString());
	      System.out.println("-----------------------------");

				System.exit(0);

	}

}
